package com.ychs.lawyer.bean;

import lombok.Getter;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: clh
 * @Date: 2024/07/25/16:08
 * @Description:
 */
@Getter
public class R<T> {
    private Integer code;
    private String msg;
    private T data;

    public R(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 不带数据的返回
     * @return
     */
    public static R success() {
        return new R(ResultCode.SUCCESS,null);
    }

//    成功带参数的返回
       public static R success(Object data) {
        return new R(ResultCode.SUCCESS,data);
    }
       public static R fail(ResultCode resultCode) {
        return new R(resultCode,null);
    }


    public static R fail(Integer code,String msg) {
        return new R(code,msg);
    }
    public static R fail() {
        return new R(ResultCode.OPERATE_EROOR,null);
    }
}
